from flask import Flask
from flask_session import Session
from config import Config,dict_config
from flask_sqlalchemy import SQLAlchemy
import logging
from logging.handlers import RotatingFileHandler

logging.basicConfig(level=logging.DEBUG)
file_log_handler = RotatingFileHandler("logs/log", maxBytes=1024*1024*100, backupCount=10)
formatter = logging.Formatter('%(levelname)s %(filename)s:%(lineno)d %(message)s')
file_log_handler.setFormatter(formatter)

logging.getLogger().addHandler(file_log_handler)
db = SQLAlchemy()


def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(dict_config[config_name])
    db.init_app(app)
    Session(app)

    from info.modules.news import news_blue
    app.register_blueprint(news_blue)

    return app